<%--
  Created by IntelliJ IDEA.
  User: zmjha
  Date: 2020/6/22
  Time: 20:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
</head>
<body>
<div>${message}</div>

<form action="register" method="post" enctype="multipart/form-data">
    用户名:<input id="userName" name="userName" type="text" onblur="checkName()" onfocus="disappear()"> <label style="color: red"></label> <br/>
    密码:<input name="password" type="text"><br/>
    确认密码:<input name="nextPassword" type="text"><br>
    验证码:<img id="img1" alt="" src="${pageContext.request.contextPath}/getCode" onclick="flash()"><input name="captcha" type="text"><br>
   头像:<input type="file" name="image" accept="image/*"/><br/>
    <input type="submit">

</form>
</body>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    function checkName(){
      var userName=$("#userName").val();
        $.ajax({
            url:"checkName",
            data:{"userName":userName},
            type:"post",
            dataType:"json",
            success:function(obj){
                console.info(obj)
                if(obj.code==0){
                    $("label").text(obj.mes);
                }else {
                    $("label").text(obj.mes);
                }
            }
        });
    }   
    
    function disappear() {
        $("label").text("");
    }
   /* function flash(obj){
        obj.src = "code?"+Math.random();
        console.info(obj.src);
    }*/
   function flash(){
    $("#img1").click(function () {
        $(this).attr('src', '${pageContext.request.contextPath}/getCode?' + Math.floor(Math.random() * 100));
    })
   }
</script>
</html>
